package com.lanou.lenanapp.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.lanou.lenanapp.R;

import java.util.ArrayList;
import java.util.Map;

/**
 * Created by dllo on 15/10/29.
 */
public class AfficheViewPagerAdapter extends PagerAdapter {

    private ImageView affiche_image;
    private TextView affiche_text;
    private ArrayList<Map<String, Object>> list;


    public void addData(ArrayList<Map<String, Object>> datas){
        this.list = datas;
        notifyDataSetChanged();
    }

    /***
     * 销毁position位置的界面
     * **/
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }


    /**
     * 获取当前界面窗体数
     * **/
    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    /**
     * 初始化position的界面
     * **/
    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        LayoutInflater inflater = LayoutInflater.from(container.getContext());
        View v = inflater.inflate(R.layout.activity_affiche_gut, null);
        affiche_image = (ImageView) v.findViewById(R.id.affiche_image);
        affiche_text = (TextView) v.findViewById(R.id.affiche_text);
        int image = (int) list.get((position%list.size())).get("image");
        String text = (String) list.get((position%list.size())).get("text");
        affiche_image.setImageResource(image);
        affiche_text.setText(text);
        container.addView(v);
        return v;
    }

    /**
     * 判断是否由对象产生界面
     * **/
    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }


}
